package com.rayson.yututu.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.rayson.yututu.model.dto.UploadPictureResult;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * 图片
 *
 * @TableName picture
 */
@TableName(value = "picture")
@Data
public class Picture implements Serializable {
    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
    /**
     * 主键id
     */
    @TableId
    private String id;
    /**
     * 图片地址
     */
    private String url;
    /**
     * 图片名称
     */
    private String name;
    /**
     * 图片简介
     */
    private String introduction;
    /**
     * 图片分类
     */
    private String category;
    /**
     * 标签（JSON 数组）
     */
    private String tags;
    /**
     * 图片体积
     */
    private Long picSize;
    /**
     * 图片宽度
     */
    private Integer picWidth;
    /**
     * 图片高度
     */
    private Integer picHeight;
    /**
     * 图片宽高比例
     */
    private Double picScale;
    /**
     * 图片格式
     */
    private String picFormat;
    /**
     * 创建用户 id
     */
    private String userId;
    /**
     * 审核状态:0-未审核,1-审核通过,2-审核不通过
     *
     * @see com.rayson.yututu.model.enums.PictureReviewStatusEnum
     */
    private Integer reviewStatus;
    /**
     * 审核信息
     */
    private String reviewMsg;
    /**
     * 审核人id
     */
    private String reviewerId;
    /**
     * 审核时间
     */
    private Date reviewTime;
    /**
     * 所属空间id
     */
    private String spaceId;
    /**
     * 是否删除:0-未删除,1-已删除
     */
    @TableLogic
    private Integer isDelete;
    /**
     * 编辑时间
     */
    private Date editTime;
    /**
     * 创建时间
     */
    private Date createTime;
    /**
     * 更新时间
     */
    private Date updateTime;

    public static Picture from(UploadPictureResult uploadPictureResult) {
        Picture picture = new Picture();
        picture.setUrl(uploadPictureResult.getUrl());
        picture.setName(uploadPictureResult.getPicName());
        picture.setPicSize(uploadPictureResult.getPicSize());
        picture.setPicWidth(uploadPictureResult.getPicWidth());
        picture.setPicHeight(uploadPictureResult.getPicHeight());
        picture.setPicScale(uploadPictureResult.getPicScale());
        picture.setPicFormat(uploadPictureResult.getPicFormat());
        return picture;
    }
}